package com.atguigu.lease.web.admin.service.impl;

import com.atguigu.lease.common.exception.StgyException;
import com.atguigu.lease.common.result.ResultCodeEnum;
import com.atguigu.lease.model.entity.LabelInfo;
import com.atguigu.lease.web.admin.mapper.AttrValueMapper;
import com.atguigu.lease.web.admin.service.AttrValueService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.atguigu.lease.model.entity.AttrValue;
import org.springframework.stereotype.Service;

/**
* @author 1
* @description 针对表【attr_value(房间基本属性值表)】的数据库操作Service实现
* @createDate 2024-08-28 11:00:25
*/
@Service
public class AttrValueServiceImpl extends ServiceImpl<AttrValueMapper, AttrValue>
    implements AttrValueService {

    @Override
    public boolean saveOrUpdateAttrValue(AttrValue attrValue) {
        long id = attrValue.getId()==null?-1L:attrValue.getId();
        AttrValue dbAttrValue = this.getOne(Wrappers.lambdaQuery(AttrValue.class)
                .eq(AttrValue::getAttrKeyId, attrValue.getAttrKeyId())
                .eq(AttrValue::getName, attrValue.getName())
                .last("limit 1"));

        if(dbAttrValue!=null && id != dbAttrValue.getId().longValue()){
            throw new StgyException(ResultCodeEnum.DATA_EXISTS_ERROR);
        }
        return this.saveOrUpdate(attrValue);
    }
}




